package tsg.graphic;

import tsg.graphic.Font;
import tsg.graphic.SystemFont;


public class PCFont implements SystemFont 
{
	public PCFont(String fontName, boolean isBold, boolean isItalic, float size)
	{
		this.setFont(fontName, isBold, isItalic, size);
	}
	
	@SuppressWarnings("deprecation")
	public void setFont(String fontName, boolean isBold, boolean isItalic, float size) 
	{
		int systemStyle = java.awt.Font.PLAIN;
		
		if(isBold == true)
		{
			systemStyle = systemStyle | java.awt.Font.BOLD;
		}
		
		if(isItalic == true)
		{
			systemStyle = systemStyle | java.awt.Font.ITALIC;
		}
		
		
		_font 		= new java.awt.Font(fontName, systemStyle, (int)size);
		_metrics 	= java.awt.Toolkit.getDefaultToolkit().getFontMetrics(_font);
	}


	public int getFontHeight() 
	{
		return _metrics.getHeight();
	}

	public int getCharacterWidth(char character) 
	{
		return _metrics.charWidth(character);
	}
	
	public Font[] getAvailableFonts() 
	{
		java.awt.GraphicsEnvironment 	graphicsEnvironment 	= java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
	    String[] 						systemFonts 			= graphicsEnvironment.getAvailableFontFamilyNames();
	    Font[] 							fonts 					= new Font[systemFonts.length];
	    
	    for(int i=0; i<fonts.length; i++) 
	    {	    	
	    	fonts[i] = new Font(systemFonts[i], Font.PLAIN, 0.0f);
	    }
		
		return fonts;
	}
	
	public java.awt.Font getAWTFont()
	{
		return _font;
	}

	private java.awt.Font 			_font 	  = null;
	private java.awt.FontMetrics  	_metrics  = null;
}
